package com.yc.jpyy.bandw.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.bandw.dao.BAndWDao;
import com.yc.jpyy.bandw.service.BAndWService;
import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.base.util.PageBean;



@Service
public class BAndWServiceImpl extends BaseService implements BAndWService {
    
	@Autowired
	private BAndWDao  bAndWDao;

	

	@Override  
	public int addBAndWService(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = bAndWDao.addBAndWDao(paramsMap);
		System.out.println(ret);
		return ret;
	}

	@Override
	public int updateBAndWService(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = bAndWDao.updateBAndWDao(paramsMap);
		return ret;
		
	}

	
	
	

	@Override
	public Map<String, Object> findBAndWDaoByIDServer(Map<String, Object> paramsMap) throws DataAccessException {
	     return bAndWDao.findBAndWByIdDao(paramsMap);
	}

	

	@Override
	public PageBean findBAndWService(Map<String, Object> paramsMap) throws DataAccessException {
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
		paramsMap.put("companyid", companyid.equals("")?"":companyid.split(","));
		List<Map<String, Object>> list = bAndWDao.findBAndWDao(paramsMap);
		PageBean pageBean = new PageBean();
		pageBean.setList(list);
		// 每页几条数据，默认20条
		pageBean.setPageSize(pagesize);
		// 得到数据库中的条数
		pageBean.setAllRow(this.findCountBAndWService(paramsMap));
		// 当前第几页，默认第一页
		pageBean.setCurrentPage(pagenum);
		// 得到一共几页
		pageBean.setTotalPage(pageBean.getTotalPage());
		// 模仿百度分页，只显示10条数据
		pageBean.paginationTool(pagenum, pageBean.getTotalPage());
		return pageBean;
	}

	@Override
	public int findCountBAndWService(Map<String, Object> paramsMap) throws DataAccessException {
		return bAndWDao.findCountBAndWDao(paramsMap);
	}

	@Override
	public int delforUpdateBAndWService(Map<String, Object> paramsMap) throws DataAccessException {
		return bAndWDao.delforUpdateBAndWDao(paramsMap);
	}

	@Override
	public int findBAndWCheckBlackService(Map<String, Object> paramsMap) throws DataAccessException {
		return bAndWDao.findBAndWCheckBlackDao(paramsMap);
	}

	@Override
	public PageBean findBAndWByPages(Map<String, Object> paramsMap)
			throws DataAccessException {
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
		paramsMap.put("companyid", companyid.equals("")?"":companyid.split(","));
		List<Map<String, Object>> list = bAndWDao.findBAndWPages(paramsMap);
		PageBean pageBean = new PageBean();
		pageBean.setList(list);
		// 每页几条数据
		pageBean.setPageSize(pagesize);
		// 得到数据库中的条数
		pageBean.setAllRow(bAndWDao.findBAndWCounts(paramsMap));
		// 当前第几页，默认第一页
		pageBean.setCurrentPage(pagenum);
		// 得到一共几页
		pageBean.setTotalPage(pageBean.getTotalPage());
		// 模仿百度分页，只显示10条数据
		pageBean.paginationTool(pagenum, pageBean.getTotalPage());
		return pageBean;
	}

	@Override
	public List<Map<String, Object>> findBAndWDaoByParamIdService(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bAndWDao.findBAndWDaoByParamIdDao(paramsMap);
	}

	@Override
	public Map<String, Object> findBAndWDaoByCompanyId(
			Map<String, Object> paramsMap) throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		//查询
		List<Map<String, Object>> list = bAndWDao.findBAndWDaoByCompanyId(paramsMap);
		if(list !=null && list.size() > 0){
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "查询成功");
			resultMap.put("ListData", list);	
		}else{
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "系统无数据");
		}
		return resultMap;
	}

	
	


	
}
